package com.t.HashMap;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentDemo {
    public static void main(String[] args) {
        try{
            ArrayList<Student> al = new ArrayList<>();
            Student s1 = new Student("小王","男",18);
            Student s2 = new Student("小张","女",17);
            Student s3 = new Student("小明","男",20);
            al.add(s1);
            al.add(s2);
            al.add(s3);
            Scanner sca = new Scanner(System.in);
            String k;
            do{
                System.out.println("1:查看学生信息");
                System.out.println("2：添加学生信息");
                System.out.println("3：删除学生");
                System.out.println("4：请输入序号选择");
                k= sca.next();
                if (k.equals("1")){
                    int i = 1;
                    for (Student student:al){
                        System.out.println("编号："+(i++)+"姓名+"+student.getName()+",性别："+student.getGender()+",年龄："+student.getAge());
                    }
                    System.out.println("查询完成");
                }else if (k.equals("2")){
                    Student s=new Student();
                    System.out.println("请输入学生姓名");
                    s.setName(sca.next());
                    System.out.println("请输入学生性别");
                    s.setGender(sca.next());
                    System.out.println("请输入学生年龄");
                    s.setAge(sca.nextInt());
                    al.add(s);
                    System.out.println("添加成功");
                } else if (k.equals("3")) {
                    System.out.println("请输入要删除的学生编号");
                    int r = sca.nextInt();
                    al.remove(r-1);
                    System.out.println("删除完成");
                }
                System.out.println("回到菜单输入y，退出程序输入任意键");
                k= sca.next();
            }while (k.equals("y"));
            System.out.println("程序运行完成");
        }catch (Exception e){
            System.out.println("输入错误，程序强制重置");
            main(args);
        }
    }
}
